<?php
$lastCate = new Shop_Category_Entity();
if(isset($category)){
    $lastCate = $category;
}
?>

<div class="row">
    <div class="col-md-12">
        <h1>Danh Mục <small>Chỉnh sửa, thêm mới danh mục</small></h1>
        <ol class="breadcrumb">
            <li><a href="<?php echo mns_page_url(); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="<?php echo mns_category_url(); ?>"><i class="fa fa-table"></i> Danh mục</a></li>
            <li class="active"><i class="fa fa-table"></i> <?php echo $lastCate->getTitle(); ?></li>
        </ol>
    </div>
</div>

<form class="form-horizontal" data-role='form' method="post" action="<?php echo mns_page_url(CATEGORY_SLUG.'/'.$action_link);?>" data-callback='1'>
    <div class="form-group">
        <label for="category_title" class="col-md-2 control-label">Tên danh mục</label>
        <div class="col-md-4">
            <input type="text" id="category_title" name="category[title]" class="form-control auto-slug" follow-ctr='#category_slug' value="<?php echo $lastCate->getTitle(); ?>" />
        </div>
    </div>
    <div class="form-group">
        <label for="category_slug" class="col-md-2 control-label">Đường dẫn</label>
        <div class="col-md-4">
            <input type="text" id="category_slug" name="category[slug]" class="form-control" value="<?php echo $lastCate->getSlug(); ?>" />
        </div>
    </div>
    <div class="form-group">
        <label for="category_cate" class="col-md-2 control-label">Danh mục cha</label>
        <div class="col-md-4">
            <select id="category_cate" name="category[cate]" class="form-control">
            <?php foreach($aParentCate as $pCate) { ?>
                <?php
                    $selected_option = "";
                    if($pCate->getId()==$lastCate->getCateId()){
                        $selected_option = "selected='selected'";
                    }
                ?>
                <option value="<?php echo $this->encrypt->encode($pCate->getId()); ?>" <?php echo $selected_option; ?>>
                    <?php echo $pCate->getTitle(); ?>
                </option>
            <?php } ?>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="category_order" class="col-md-2 control-label">Thứ tự</label>
        <div class="col-md-2">
            <input type="text" id="category_order" name="category[order]" class="form-control" value="<?php echo $lastCate->getOrder(); ?>" />
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-4">
            <div class="checkbox">
                <label>
                    <input name="category[delete_flg]" type="checkbox" value="1" <?php if($lastCate->getDeletedAt()!=NULL) { ?> checked="checked" <?php } ?> /> Xoá
                </label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <?php
            $curCateId = "";
            $btnText = "";
            if(isset($category)){
                $btnText = "Cập nhật";
                $lastCateId = $this->encrypt->encode($lastCate->getId());
                $curCateId = "<input type='hidden' name='category[id]' value='{$lastCateId}' />";
            } else {
                $btnText = "Thêm";
            }
            echo $curCateId;
        ?>
        <div class="col-md-4 col-md-offset-2">
            <button type="button" class="btn btn-primary btn-submit-update">
                <i class='glyphicon glyphicon-ok-sign'></i>
                <?php echo $btnText; ?>
            </button>
            <a href="<?php echo mns_category_url(); ?>" class="btn btn-default">
                <i class='glyphicon glyphicon-share-alt'></i>
                Trở về
            </a>
        </div>
    </div>
</form>